package pers.yurwisher.dota2.pudge.system.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.yurwisher.dota2.pudge.base.BaseController;
import pers.yurwisher.dota2.pudge.system.pojo.fo.SystemFaqFo;
import pers.yurwisher.dota2.pudge.system.pojo.qo.SystemFaqQo;
import pers.yurwisher.dota2.pudge.system.pojo.to.SystemFaqTo;
import pers.yurwisher.dota2.pudge.system.pojo.vo.SystemFaqVo;
import pers.yurwisher.dota2.pudge.system.service.ISystemFaqService;
import pers.yurwisher.dota2.pudge.wrapper.PageR;
import pers.yurwisher.dota2.pudge.wrapper.R;

/**
 * @author yq
 * @date 2021-03-03 11:07:55
 * @description FAQ常见问题解答
 * @since V1.0.0
 */
@RestController
@RequestMapping("/faq")
public class SystemFaqController extends BaseController {
    private ISystemFaqService systemFaqService;

    public SystemFaqController(ISystemFaqService systemFaqService) {
        this.systemFaqService = systemFaqService;
    }

    @PostMapping
    public R<String> create(@RequestBody @Validated SystemFaqFo fo) {
        systemFaqService.create(fo);
        return R.ok();
    }

    @PostMapping("{id}")
    public R<String> update(@PathVariable(name = "id") Long id, @RequestBody @Validated SystemFaqFo fo) {
        systemFaqService.update(id, fo);
        return R.ok();
    }

    @GetMapping("{id}")
    public R<SystemFaqVo> get(@PathVariable(name = "id") Long id) {
        return R.ok(systemFaqService.get(id));
    }

    @PostMapping("/delete/{id}")
    public R<String> delete(@PathVariable(name = "id") Long id) {
        systemFaqService.delete(id);
        return R.ok();
    }

    @GetMapping
    public R<PageR<SystemFaqTo>> list(@ModelAttribute SystemFaqQo qo) {
        return R.ok(systemFaqService.list(qo));
    }


}
